<?php
require_once dirname(__FILE__).'/include.php';
Master::loadCoreClass("AdminControl");
$Admin = new AdminControl();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=Config::$siteName ?></title>    
<?php
require_once dirname(__FILE__).'/heard.php';
?> 	
</head>
<body>
<?php
if (Get::getByKey('action')=='save')
{	
	//$mydb->db->update('fileditems',array('fieldCN'=>Post::getByKey('fieldCN')),array('fieldName'=>Post::getByKey('fieldName'),'tableName'=>Post::getByKey('tableName')));	
	$tablename = Post::getByKey('tableName');
	$filename = Post::getByKey('fieldName');
	$filedtype = Post::getByKey('datatype');
	if ($filedtype!='')
		//$Admin->execute("ALTER TABLE ".$tablename." CHANGE ".$filename." ".$filename." ".$filedtype."; ");
	$Admin ->createfileditems();
	Header("Location:databasehelper.php?tableName=".$tablename);
	exit();
}else if (Get::getByKey('action')=='create')
{
	$tablename = Post::getByKey('tableName');
	$filename = Post::getByKey('fieldName');
	$filedtype = Post::getByKey('datatype');
	if ($filedtype!='')
		$filedtype = "varchar(20)";
	//$Admin->execute("ALTER TABLE ".$tablename." ADD  ".$filename." ".$filedtype."; ");
	$Admin ->createfileditems();
	Header("Location:databasehelper.php?tableName=".$tablename);
	exit();	
}else if ( Get::getByKey('action')=='del'){
	$tablename = Get::getByKey('tableName');
	$filename = Get::getByKey('fieldName');
	//$Admin->execute("ALTER TABLE ".$tablename." DROP ".$filename.";");
	$Admin->delfileditems(Get::getByKey('id'));
	Header("Location:databasehelper.php?tableName=".$tablename);
	exit();  
}
$Ar = $Admin->showFields(Get::getByKey('tableName'));
foreach($Ar as $key)
{
	if (count($Admin->select('fileditems',array('tableName'=>Get::getByKey('tableName'),'fieldName'=>$key['Field'])))<1)
		$Admin->insert('fileditems',array('tableName'=>Get::getByKey('tableName'),'fieldName'=>$key['Field']));
}

$Arr= $Admin->showfileditems(array('tableName'=>Get::getByKey('tableName')));
?>
<div id="main-content">		
				<div class="content-box">
				<div class="content-box-header">					
					<h3>当前位置：<?=Config::$siteName ?>管理系统 &gt; 开发助手(<?=Get::getByKey('tableName')?> 表单设计)</h3>					
					<ul class="content-box-tabs">
						<li><a href="#tab1" class="default-tab">列表</a></li>
					</ul>					
					<div class="clear"></div>					
				</div> 
				<div class="content-box-content">				
					<div class="tab-content default-tab" id="tab1"> 											
						<table>							
							<thead>
								<tr>
								   <th>字段名称</th>
								   <th>中文名称</th>
								   <th>数据类型</th>
								   <th>表单类型</th>
								   <th>主键</th>
								   <th>排序</th>
								   <th>列表显示</th>
								   <th>管理&nbsp;&nbsp;</th>								   
								</tr>
							</thead>
							<tfoot>
								<tr>
									<td colspan="8">				
									<?=$Admin->showPages()?>						
									</td>
								</tr>
							</tfoot>
							<tbody>
   <?php
		foreach($Arr as $key){
    ?> 					<form action="?action=save" method="post">
								<tr>
									<td><?=$key->fieldName?></td>
									<td>
									<input type="hidden" id="tableName" name="tableName"  value="<?=Get::getByKey('tableName')?>" />
									<input type="hidden" id="fieldName" name="fieldName"  value="<?=$key->fieldName?>" />
									<input type="hidden" id="id" name="id"  value="<?=$key->id?>" />
									<input class="text-input" type="text" size="8" id="fieldCN" name="fieldCN" value="<?=$key->fieldCN?>" /></td>
									
									<td><?=selectdataType('datatype',$key->datatype)?></td>
									<td><?=selectHtmlType('htmltype',$key->htmltype)?></td>
									<td><?=Checkbox('fieldpri','1',$key->fieldpri)?></td>
									<td><input class="text-input" type="text" id="orderpri" name="orderpri" value="<?=$key->orderpri?>" size="2" /></td>
									<td><?=Checkbox('listshow','1',$key->listshow)?></td>
									<td>
									<input  type="submit"  value="更新"/>
										 <a href="adminhelpermod.php?tableName=<?=$key->Name?>" title="数据库管理"><img src="Images/icons/hammer_screwdriver.png" alt="数据库管理" /></a><a href="?action=del&id=<?=$key->id?>&fieldName=<?=$key->fieldName?>&tableName=<?=Get::getByKey('tableName')?>" title="Delete"><img src="Images/icons/cross.png" alt="Delete" /></a>
									</td>
								</tr>		
								</form>												
	<?
		}
	?>
								<form action="?action=create" method="post">
								<input type="hidden" id="tableName" name="tableName"  value="<?=Get::getByKey('tableName')?>" />
								<tr>
									<td><input class="text-input" type="text" size="8" id="fieldName" name="fieldName" /></td>
									<td><input class="text-input" type="text" size="8" id="fieldCN" name="fieldCN" /></td>
							
									<td><?=selectdataType('datatype')?></td>
							
									<td><?=selectHtmlType('htmltype')?></td>
					
									<td><input type="checkbox" id=fieldpri name=fieldpri  value=1  /></td>
																																								
									<td><input class="text-input" type="text" id="orderpri" name="orderpri" size="2" /></td>							
									<td><input type="checkbox" id=listshow name=listshow  value=1  /></td>
									<td><input  type="submit"  value="创建"/></td>
								</tr>	
								</form>
								<form action="viewform.php?tablename=<?=Get::getByKey('tableName')?>" method="post">
								<tr>								
									<td>表单目录</td>												
									<td colspan="3"><input class="text-input" type="text" size="40" id="formdir" name="formdir" value="<?=dirname(__FILE__)?>" /></td>		
									<td></td>																																									
									<td></td>							
									<td></td>
									<td><input  type="submit"  value="生成表单"/></td>
								</tr>	
																
							</tbody>
						</table>		
					</div>
					
				</div> 
</div>
</div>

</body>  
</html>
